{include file='common/head.html'}

<div class="layui-body">
    <div class="layui-tab layui-tab-brief" lay-filter="tab">
        <ul class="layui-tab-title">
            <li class="layui-this" lay-id="t1">会员排单池订单</li>
            <li lay-id="t2">订单池列表</li>
            <li lay-id="t3">订单池新增</li>
        </ul>
        <div class="layui-tab-content ">
            <div class="layui-tab-item layui-show">
                <form action="{url./admin/Scheduling/schedulinglist}" method="get" class="layui-form">
                    <div class="layui-form-item nospace">
                        <div class="layui-input-inline">
                            {$pathinfo}
                            <select name="field" lay-verify="required">
                                <option value="u.usermobile" {if(get('field')=='u.usermobile')}selected="selected" {/if}>会员用户名</option>

                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" name="keyword"  value="{$get.keyword}"  placeholder="请输入搜索关键字" class="layui-input">
                        </div>
                        <div class="layui-input-inline">
                            <button class="layui-btn" lay-submit>搜索</button>
                            <a class="layui-btn layui-btn-primary"  href="{url./admin/Member/index}">清除搜索</a>
                        </div>
                    </div>
                </form>


                <input type="hidden" name="formcheck" value="{$formcheck}" >
                <table class="layui-table">
                    <thead>
                    <tr>
                        <th><input type="checkbox" class="checkbox" lay-ignore id="checkall" title="全选"></th>
                        <th>编号</th>
                        <th>用户名</th>
                        <th>排单名</th>
                        <th>金额</th>
                        <th>状态</th>
                        <th>排单时间</th>

                        <!--<th>操作</th>-->
                    </tr>
                    </thead>
                    <tbody>
                    {foreach $PoolList(key,value)}
                    <tr>
                        <td>
                            <input type="checkbox" class="checkbox checkitem" lay-ignore name="list[]" value="[value->id]">
                            <input type="hidden" name="listall[]" value="[value->id]">
                        </td>
                        <td>[value->id]</td>
                        <td>[value->usermobile]</td>
                        <td>[value->pname]</td>

                        <td>[value->quota]</td>

                        <td>
                            {if($value->status)}
                            失败
                            {else}
                            成功
                            {/if}
                        </td>
                        <td>[value->add_time]</td>

                        <!--<td>-->
                        <!--{fun=get_btn_more($value->id)}-->
                        <!--{fun=get_btn_del($value->id)}-->
                        <!--{fun=get_btn_mod($value->id)}-->
                        <!--</td>-->
                    </tr>

                    {/foreach}
                    </tbody>
                </table>


                <div class="page">{$pagebar}</div>
            </div>
            <div class="layui-tab-item ">
                <table class="layui-hide" id="demo" lay-filter="test"></table>
                <script type="text/html" id="toolbarDemo">
                    <div class="layui-row">
                        <div class="layui-col-md2 layui-col-sm3 layui-col-xs6" style="text-align: left;padding-left: 10px;">
                            <div class="layui-input-inline yutons-btn-margin-right">
                                <span class="layui-btn yutons layui-btn-sm yutons-color-detail" lay-event="table_export">导出</span>
                            </div>
                        </div>

                    </div>
                </script>
                <script type="text/html" id="barDemo">
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" >删除</a>
                </script>
            </div>

            <div class="layui-tab-item">
                <form action="{url./admin/Scheduling/SchedulingAdd}" method="post" class="layui-form">
                    <input type="hidden" name="formcheck" value="{$formcheck}" >

                    <div class="layui-form-item">
                        <label class="layui-form-label">抢单名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="pname" required lay-verify="required"  placeholder="抢单名称" class="layui-input">
                        </div>
                    </div>


                    <div class="layui-form-item">

                            <label class="layui-form-label">抢购金额</label>
                            <div class="layui-input-inline" >
                                <input type="number" min=0  name="qauota" placeholder="￥" autocomplete="off" class="layui-input">
                            </div>

                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">开始时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="begin_time" required  readonly placeholder="请选择开始时间"  class="layui-input datetime">

                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">结束时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="end_time"  required readonly placeholder="请选择结束时间"  class="layui-input datetime">

                            </div>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">是否启用</label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" value="1" title="开始" checked>
                            <input type="radio" name="status" value="2" title="结束">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit>立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>


</div>

{include file='common/foot.html'}
<script>
    layui.config({
        base: '{APP_THEME_DIR}/layui/excel.js'
    }).use(['table', 'excel'], function() {
        var table = layui.table //表格,
            $ = layui.$,
            excel = layui.excel;
        //执行一个 table 实例
        table.render({
            elem: '#demo',
            url: '{url./admin/Scheduling/schedulinglistJson}', //数据接口
            title: '订单池列表',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: [ 'count', 'prev', 'page', 'next'] //自定义分页布局



            },
            toolbar: '#toolbarDemo', //操作1:启用自定义模板表格头部工具栏

            defaultToolbar: [], //操作2:隐藏头部工具栏右侧的图标
                    cols: [[
                         {type: 'checkbox', fixed: 'left'}
                        ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
                        ,{field:'pname', title:'抢单名称'}
                        ,{field:'sauota', title:'剩余额度',  sort: true}
                        ,{field:'qauota', title:'抢购金额',   sort: true}
                        ,{field:'qauota', title:'抢购金额',   sort: true}
                        ,{field:'status', title:'状态' ,templet: function(res){
                             if(res.status==1){
                                 return '开始'
                             }else {
                                 return ' 结束'
                             }
                            }}
                        ,{field:'begin_time', title:'开始时间' ,  sort: true}
                        ,{field:'end_time', title:'结束时间' ,  sort: true}
                        ,{field:'add_time', title:'添加时间' ,  sort: true}
                        ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
                    ]]
        });

        //监听头工具栏事件
        table.on('toolbar(test)', function(obj) {
            var checkStatus = table.checkStatus(obj.config.id),
                data = checkStatus.data; //获取选中的数据


            switch (obj.event) {
                case 'table_export':
                    exportFile('demo')
                    break;
            };
        });
        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){

                    $.ajax({
                        //几个参数需要注意一下
                        type: 'GET',//方法类型
                        dataType: "json",//预期服务器返回的数据类型
                        url:'{url./admin/Scheduling/del}',//url
                        data: data,
                        async : false,
                        cache: false,        // 不缓存数据
                        success: function (res) {
                            if (res.code == 1) {
                                layer.msg(res.data, {
                                    icon: 1,
                                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                                }, function(){
                                    //do something
                                    location.reload();
                                });

                            } else {
                                layer.msg(res.data, {
                                    icon: 2,
                                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                                }, function(){
                                    //do something
                                    location.reload();
                                });


                            }
                        },

                    });

                });
            }
        });
        /**
         * by yutons
         * Array.from() 非常方便的将一个类数组的集合 ==》 数组，直接使用数组身上的方法。例如：常用的map，foreach…
         * 但是，问题来了，IE不识别Array.from这个方法。所以写了它兼容IE的写法。
         */
        if (!Array.from) {
            Array.from = function(el) {
                return Array.apply(this, el);
            }
        }
        //表格导出
        function exportFile(id) {
            //根据传入tableID获取表头
            var headers = $("div[lay-id=" + id + "] .layui-table-box table").get(0);
            var htrs = Array.from(headers.querySelectorAll('tr'));
            var titles = {};
            for (var j = 0; j < htrs.length; j++) {
                var hths = Array.from(htrs[j].querySelectorAll("th"));
                for (var i = 0; i < hths.length; i++) {
                    var clazz = hths[i].getAttributeNode('class').value;
                    if (clazz != ' layui-table-col-special' && clazz != 'layui-hide') {
                        //排除居左、具有、隐藏字段
                        //修改:默认字段data-field+i,兼容部分数据表格中不存在data-field值的问题
                        titles['data-field' + i] = hths[i].innerText;
                    }
                }
            }
            //根据传入tableID获取table内容
            var bodys = $("div[lay-id=" + id + "] .layui-table-box table").get(1);
            var btrs = Array.from(bodys.querySelectorAll("tr"))
            var bodysArr = new Array();
            for (var j = 0; j < btrs.length; j++) {
                var contents = {};
                var btds = Array.from(btrs[j].querySelectorAll("td"));
                for (var i = 0; i < btds.length; i++) {
                    for (var key in titles) {
                        //修改:默认字段data-field+i,兼容部分数据表格中不存在data-field值的问题
                        var field = 'data-field' + i;
                        if (field === key) {
                            //根据表头字段获取table内容字段
                            contents[field] = btds[i].innerText;
                        }
                    }
                }
                bodysArr.push(contents)
            }
            //将标题行置顶添加到数组
            bodysArr.unshift(titles);
            //导出excel
            excel.exportExcel({
                sheet1: bodysArr
            }, '订单池列表' + new Date().toLocaleString() + '.xlsx', 'xlsx');

        }
    });
</script>
